package com.xl.controller;

import com.xl.domain.entity.ResponseResult;
import com.xl.domain.entity.User;
import com.xl.enums.AppHttpCodeEnum;
import com.xl.exception.SystemException;
import com.xl.service.BlogLoginService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController

public class BlogLoginController {
    @Resource
    private BlogLoginService blogLoginService;

    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user) {
        if (!StringUtils.hasText(user.getUserName())){
            //提示 必须要传用户名
          throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        return blogLoginService.login(user);
    }
    @PostMapping("/logout")
    public ResponseResult logout() {
        return blogLoginService.logout();
    }

    Logger logger = LogManager.getLogger(BlogLoginController.class);

    @GetMapping("/test")
    public ResponseResult testLog(){
        logger.debug("我是debug,调试日志");
        logger.info("info,正常的日志输出");
        logger.warn("warning,警告,可能触发异常");
        logger.error("error,产生了异常,程序终止,或者中断");
        return ResponseResult.okResult();
    }


}
